//对外暴露封装请求
//url请求地址
export const request = (params) => {
  //服务器基础路径
  let baseURL = 'https://gmall-prod.atguigu.cn'
  wx.showLoading({
    title: '正在加载....',
  })
  //微信内置请求方法
  return new Promise((resolve, reject) => {
    let header = {
      "Content-type":'application/json'
    };
    let token = wx.getStorageSync('TOKEN');
    token && (header.token = token);

    wx.request({
      url: baseURL + params.url, //请求地址
      data: params.data || {},
      method: params.method || 'get',
      header,
      success(res) {
        wx.hideLoading()
        resolve(res.data);
      },
      fail(error) {
        reject(error);
      },
      timeout: 5000
    })
  })
};